package com.lk.client.loadbanlance;

import com.lk.entity.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 轮训
 *
 * @author kun.li
 */
public class RoundRoute implements Route {

    private final AtomicInteger count = new AtomicInteger(0);


    @Override
    public Service switchService(Set<Service> serviceSet) {
        List<Service> list = new ArrayList<>(serviceSet);
        return list.get(count.getAndIncrement() % list.size());
    }
}
